var banner = document.getElementById('banner');
var iNow = 0; // 定义当前是第几张
var pre = 0;
var arrBg = document.getElementById('banner_bg').children; // 获取三个背景图
var arrBanA = document.getElementById('ws_images').getElementsByTagName('a');  // 获取三个 A 标签

// var ifMove = false;
var timer = null;


var ws_next=document.getElementById('ws_next');
var ws_prev=document.getElementById('ws_prev');

ws_next.onclick = nextP;

ws_prev.onclick = function(){
	iNow --;
	iNow = (iNow+arrBanA.length)%arrBanA.length;
	pre = (iNow+1)%arrBanA.length;
	showView(iNow,pre);
	
}
// 自动下一张
clearInterval(timer);
timer = setInterval(function(){
	nextP();
},2000);

banner.onmouseover = function(){
	clearInterval(timer);
}
banner.onmouseout = function(){
	clearInterval(timer);
	timer = setInterval(function(){
		nextP();
	},2000);
}

// 下一张
function nextP(){
	iNow ++;
	iNow = iNow%arrBanA.length;
	pre = (iNow-1+arrBanA.length)%arrBanA.length;
	showView(iNow,pre);
}
// 定义运动函数
function showView(num,pre){
	// alert(num);
	// 之前的隐藏，下一张显示
	startMove(arrBg[pre],{opacity:0},function(){

	});
	startMove(arrBg[num],{opacity:100},function(){
		//iNow = num;
	});
	startMove(arrBanA[pre],{opacity:0},function(){

	});
	startMove(arrBanA[num],{opacity:100},function(){
		//ifMove = !ifMove;
	});
}


/* 热门品牌 */
var arrMain = $('.list-pin')
var arrHotA = $('#hot-tab a');
var numHot = 0; // 定义当前显示的第几个
var onHot = true;//定义一个开关，开的时候可以运动
arrHotA[0].onclick = function(){
	if(onHot){
		var pre = numHot+1;
		pre = (pre)% arrMain.length;
		hotMove(pre,true);
	}
	onHot = false;
}
arrHotA[1].onclick = function(){
	if(onHot){
		var nex = numHot-1;
		nex = (nex+arrMain.length)% arrMain.length;
		hotMove(nex);
	}
	onHot = false;
}

function hotMove(nex,on){
	arrMain[nex].style.left = on==true?'997px':'-997px';
	//alert(on==true?997:-997);
	startMove(arrMain[nex],{left:0},function(){
		arrMain[nex].style.left = '-1px';
		numHot = nex;
	});
	startMove(arrMain[numHot],{left:on==true?-997:997 },function(){
		onHot = true;
	});
}









